package com.fr.report.web;

import com.fr.base.FRContext;
import com.fr.base.core.BaseCoreUtils;
import com.fr.base.core.Mapper;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import com.fr.report.web.ui.Button;
import com.fr.report.web.ui.ToolBar;
import com.fr.report.web.ui.Widget;
import com.fr.report.web.ui.impl.Email;
import com.fr.report.web.ui.impl.Excel;
import com.fr.report.web.ui.impl.Export;
import com.fr.report.web.ui.impl.FlashPrint;
import com.fr.report.web.ui.impl.PDF;
import com.fr.report.web.ui.impl.PDFPrint;
import com.fr.report.web.ui.impl.Print;
import com.fr.report.web.ui.impl.ServerPrint;
import com.fr.report.web.ui.impl.page.First;
import com.fr.report.web.ui.impl.page.Last;
import com.fr.report.web.ui.impl.page.Next;
import com.fr.report.web.ui.impl.page.PageNavi;
import com.fr.report.web.ui.impl.page.Previous;
import com.fr.report.web.ui.impl.write.AppendColumnRow;
import com.fr.report.web.ui.impl.write.ShowCellValue;
import com.fr.report.web.ui.impl.write.Submit;
import com.fr.report.web.ui.impl.write.Verify;
import com.fr.web.Repository;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ToolBarManager
  implements Serializable, Cloneable, XMLReadable
{
  public static final String XML_TAG = "ToolBarManager";
  private Location toolBarLocation;
  private ToolBar toolBar;

  public static ToolBarManager createDefaultToolBar()
  {
    ToolBarManager localToolBarManager = new ToolBarManager();
    localToolBarManager.setToolBar(new ToolBar(new Widget[] { new First(), new Previous(), new PageNavi(), new Next(), new Last(), new FlashPrint(), new Print(), new Export(), new Email() }));
    return localToolBarManager;
  }

  public static ToolBarManager createPrintPreviewToolBar()
  {
    ToolBarManager localToolBarManager = new ToolBarManager();
    localToolBarManager.setToolBar(new ToolBar(new Widget[] { new First(), new Previous(), new PageNavi(), new Next(), new Last(), new FlashPrint(), new Print(), new Export() }));
    return localToolBarManager;
  }

  public static ToolBarManager createDefaultFormToolBar()
  {
    ToolBarManager localToolBarManager = new ToolBarManager();
    localToolBarManager.setToolBar(new ToolBar(new Widget[] { new FlashPrint(), new Print(), new Export(), new Email() }));
    return localToolBarManager;
  }

  public static ToolBarManager createDefaultWriteToolBar()
  {
    ToolBarManager localToolBarManager = new ToolBarManager();
    localToolBarManager.setToolBar(new ToolBar(new Widget[] { new Submit(), new Verify(), new FlashPrint(), new Print(), new Export(), new Email(), new AppendColumnRow(), new ShowCellValue() }));
    return localToolBarManager;
  }

  public Location getToolBarLocation()
  {
    return this.toolBarLocation;
  }

  public void setToolBarLocation(Location paramLocation)
  {
    this.toolBarLocation = paramLocation;
  }

  public ToolBar getToolBar()
  {
    return this.toolBar;
  }

  public void setToolBar(ToolBar paramToolBar)
  {
    this.toolBar = paramToolBar;
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("ToolBarManager");
    Location.writeXML(this.toolBarLocation, paramXMLPrintWriter);
    if (this.toolBar != null)
      this.toolBar.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.end();
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    Object localObject;
    if (paramXMLableReader.isAttr())
    {
      String str;
      if ((str = paramXMLableReader.getAttr("toolbarPosition")) != null)
        setToolBarLocation(Location.createEmbedLocation(Integer.parseInt(str)));
      localObject = new ArrayList();
      ((List)localObject).add(new First());
      ((List)localObject).add(new Previous());
      ((List)localObject).add(new PageNavi());
      ((List)localObject).add(new Next());
      ((List)localObject).add(new Last());
      boolean bool1 = true;
      boolean bool2 = true;
      if ((str = paramXMLableReader.getAttr("isIconVisible")) != null)
        bool1 = Boolean.valueOf(str).booleanValue();
      if ((str = paramXMLableReader.getAttr("isTextVisible")) != null)
        bool2 = Boolean.valueOf(str).booleanValue();
      if (((str = paramXMLableReader.getAttr("isShowFlashPrint")) != null) && (Boolean.valueOf(str).booleanValue()))
        ((List)localObject).add(new FlashPrint());
      if (((str = paramXMLableReader.getAttr("isShowPDFPrint")) != null) && (Boolean.valueOf(str).booleanValue()))
        ((List)localObject).add(new PDFPrint());
      if (((str = paramXMLableReader.getAttr("isShowPDF")) != null) && (Boolean.valueOf(str).booleanValue()))
        ((List)localObject).add(new PDF());
      if (((str = paramXMLableReader.getAttr("isShowExcel")) != null) && (Boolean.valueOf(str).booleanValue()))
        ((List)localObject).add(new Excel());
      if (((str = paramXMLableReader.getAttr("isShowPrint")) != null) && (Boolean.valueOf(str).booleanValue()))
        ((List)localObject).add(new ServerPrint());
      if (((str = paramXMLableReader.getAttr("isShowExport")) != null) && (Boolean.valueOf(str).booleanValue()))
        ((List)localObject).add(new Export());
      if (((str = paramXMLableReader.getAttr("isShowEmail")) != null) && (Boolean.valueOf(str).booleanValue()))
        ((List)localObject).add(new Email());
      if (!(bool1))
        BaseCoreUtils.map((List)localObject, new Mapper(this)
        {
          private final ToolBarManager this$0;

          public Object map(, Object paramObject, List paramList)
          {
            ((Button)paramObject).setIconName(null);
            return paramObject;
          }
        });
      if (!(bool2))
        BaseCoreUtils.map((List)localObject, new Mapper(this)
        {
          private final ToolBarManager this$0;

          public Object map(, Object paramObject, List paramList)
          {
            ((Button)paramObject).setText(null);
            return paramObject;
          }
        });
      if (((List)localObject).size() > 0)
        this.toolBar = new ToolBar((Widget[])((List)localObject).toArray(new Widget[((List)localObject).size()]));
    }
    if (paramXMLableReader.isChildNode())
    {
      localObject = paramXMLableReader.getTagName();
      if ("ToolBar".equals(localObject))
      {
        this.toolBar = new ToolBar();
        paramXMLableReader.readXMLObject(this.toolBar);
      }
      else if ("Location".equals(localObject))
      {
        this.toolBarLocation = Location.readXML(paramXMLableReader);
      }
    }
  }

  public JSONObject toJSONConfig(Repository paramRepository)
  {
    JSONObject localJSONObject1 = new JSONObject();
    Location localLocation = getToolBarLocation();
    if (localLocation == null)
      localLocation = Location.createTopEmbedLocation();
    if (localLocation instanceof Location.Embed)
    {
      try
      {
        localJSONObject1.put("position", (((Location.Embed)localLocation).getPosition() == 1) ? "north" : "south");
      }
      catch (JSONException localJSONException1)
      {
        FRContext.getLogger().log(Level.WARNING, localJSONException1.getMessage(), localJSONException1);
      }
    }
    else if (getToolBarLocation() instanceof Location.Float)
    {
      int i = ((Location.Float)localLocation).getTop();
      int j = ((Location.Float)localLocation).getBottom();
      int k = ((Location.Float)localLocation).getLeft();
      int l = ((Location.Float)localLocation).getRight();
      try
      {
        JSONObject localJSONObject2 = new JSONObject();
        if (i >= 0)
          localJSONObject2.put("top", i);
        if (j >= 0)
          localJSONObject2.put("bottom", j);
        if (k >= 0)
          localJSONObject2.put("left", k);
        if (l >= 0)
          localJSONObject2.put("right", l);
        localJSONObject1.put("position", localJSONObject2);
      }
      catch (JSONException localJSONException3)
      {
        FRContext.getLogger().log(Level.WARNING, localJSONException3.getMessage(), localJSONException3);
      }
    }
    try
    {
      localJSONObject1.put("toolbarConf", getToolBar().createJSONConfig(paramRepository));
    }
    catch (JSONException localJSONException2)
    {
      FRContext.getLogger().log(Level.WARNING, localJSONException2.getMessage(), localJSONException2);
    }
    return localJSONObject1;
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    ToolBarManager localToolBarManager = (ToolBarManager)super.clone();
    if (this.toolBar != null)
      localToolBarManager.toolBar = ((ToolBar)this.toolBar.clone());
    return localToolBarManager;
  }
}